
using UnityEngine;

public class IconSetupper
{
	string LevelPrefabPath = "Prefab/LevelTexture";
	GameObject LevelGridGO = GameObject.FindWithTag("LevelGrid");

	public void SetupLevelIcon(int index, string IconPath)
	{
		Texture levelTex = Resources.Load(IconPath) as Texture;
		DebugUtil.Assert(levelTex != null, "IconPath: "+IconPath+" Not Exist.");

		Object prefab = Resources.Load(LevelPrefabPath);
		DebugUtil.Assert(prefab != null, "PrefabPath: "+LevelPrefabPath+" Not Exist.");

		GameObject levelGO = GameObject.Instantiate(prefab) as GameObject;
		levelGO.GetComponent<UITexture>().mainTexture = levelTex;

		levelGO.transform.parent = LevelGridGO.transform;
		LevelGridGO.GetComponent<UIGrid>().Reposition();

		levelGO.AddComponent<LevelIconComponent>().Index = index;
		levelGO.transform.localScale = Vector3.one;
	}
}